package com.ty.controller;

import com.ty.entity.PoItem;
import com.ty.entity.PoItemQuery;
import com.ty.service.PoItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//restfullApi
@RequestMapping("/api/po")
//@CrossOrigin(origins = "*") // 解决跨域问题
//@NoWapperX
public class PoItemController {

    @Autowired
    private PoItemService poitemService;

    @GetMapping// 查询 万能接口 ?id=1  ?ids=1,2,3 ?name=小米  ?categoryId=2
    public List<PoItem> select (PoItemQuery query) {
        //验证token

        return poitemService.select(query);
    }

    @PostMapping
    public Integer insert(@RequestBody PoItem poitem){
        return poitemService.insert(poitem);
    }

    @PutMapping //从http协议的请求体
    public int update(@RequestBody PoItem poitem) {
        return  poitemService.update(poitem);
    }

    @DeleteMapping //@RequestParam要求 url 上面一定要传参数 ?id=3
    public int delete(@RequestParam Integer id){
        return poitemService.delete(id);
    }

}
